<template>
    <div style="padding:20px;">
        <!--部门简介-->
        <div v-if="departObj.isEditor" style="padding:0 100px 10px 0">
            <el-upload
            class="upload-demo"
            :action="action"
            :with-credentials="true"
            :on-success="handleSuccess"
            :accept="accept"
            :limit="1"
            :show-file-list="false">
            <el-button size="small" type="primary" icon="el-icon-upload2">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传jpg/png文件，且不超过500kb</div>
            </el-upload>
        </div>
        <div style="text-align:center;">
            <img v-if="picUrl!==''"  :src="picUrl" style="max-width:100%;"/>
        </div>
        
        <el-form label-width="280px">
            <el-form-item label="西安长城出租车公司：">
                {{form.ccczgs}}
            </el-form-item>
            <el-form-item label="出租公司服务部：">
                {{form.czfwb}}
            </el-form-item>
            <el-form-item label="万里：">
                {{form.wanli}}
            </el-form-item>
            <el-form-item label="福华：">
                {{form.fuhua}}
            </el-form-item>
            <el-form-item label="前进：">
                {{form.qianjin}}
            </el-form-item>
            <el-form-item label="亚辉：">
                {{form.yahui}}
            </el-form-item>
            <el-form-item label="财力：">
                {{form.caili}}
            </el-form-item>
            <el-form-item label="星光：">
                {{form.xingguang}}
            </el-form-item>
            <el-form-item label="伊兰：">
                {{form.yilan}}
            </el-form-item>
            <el-form-item label="世园旅游：">
                {{form.shiyuanly}}
            </el-form-item>
            <el-form-item label="天子：">
                {{form.tianzi}}
            </el-form-item>
            <el-form-item label="亚美：">
                {{form.yamei}}
            </el-form-item>
            <el-form-item label="公交万里实业公司：">
                {{form.gjwanli}}
            </el-form-item>
            <el-form-item label="西安市精典出租汽车有限公司：">
                {{form.jdcz}}
            </el-form-item>
            <el-form-item label="西安市出租汽车公司西旅分公司：">
                {{form.xlfgs}}
            </el-form-item>
            <el-form-item label="顺达：">
                {{form.shunda}}
            </el-form-item>
            <el-form-item label="西城：">
                {{form.xicheng}}
            </el-form-item>
            <el-form-item label="滴滴：">
                {{form.didi}}
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import api from '@/ajax/api-sl';
export default {
    data(){
        return {
            action: api.upload,
            picUrl: '',
            accept:'image/*',
            form:{
                departmentImg:'https://wx4.sinaimg.cn/mw690/6900c5b5ly1g76s5gxxerj20go0p041q.jpg',//部门图片
                ccczgs:'长城管理员',//西安长城出租车公司
                czfwb:'服务部',//出租公司服务部
                wanli:'万里管理',//万里
                fuhua:'福华',//福华
                qianjin:'前进管理员',//前进
                yahui:'yhadmin',//亚辉
                caili:'cladmin',//财力
                xingguang:'星光管理',//星光
                yilan:'yladmin',//伊兰
                shiyuanly:'世园旅游',//世园旅游
                tianzi:'天子管理员',//天子
                yamei:'ymadmin',//亚美
                gjwanli:'公交万里',//公交万里实业公司
                jdcz:'jd',//西安市精典出租汽车有限公司
                xlfgs:'西旅',//西安市出租汽车公司西旅分公司
                shunda:'顺达',//顺达
                xicheng:'西城管理员',//西城
                didi:'滴滴，wycadmin'//滴滴
            },
            fileList:[
                {name:'',url:''}
            ]
        }
    },
    props:['departObj'],
    mounted(){
        // this.accept = Object.assign({},this.accept,this.departObj.accept);
        this.reload()
    },
    methods:{
        handleSuccess(res, file, fileList) {
            if (res.code === '00000') {
                this.saveDepartment(res.data.fileName);
                this.picUrl = api.imgHost + res.data.fileName;
            }
        },
        async reload () {
            this.user = await api.getUserByUserName(JSON.parse(sessionStorage.getItem('user')).username)
            const res = await api.getBasicDepartment({departmentId: this.user.data.orgid});
            if (res.code === '00000') {
                if(res.data) {
                    this.picUrl = api.imgHost + res.data.picUrl;
                } else {
                    this.picUrl = ''
                }
            } else {
                this.$message.error(res.message);
            }
        },
        async saveDepartment(picUrl){
            const res = await api.editBasicDepartment({departmentId: this.user.data.orgid, picUrl: picUrl})
            if (res.code === '00000') {
                this.$message.success('提交保存成功')
          } else {
                this.$message.error(res.message);
          }
        }
    }
}
</script>